<?php
class AppController extends Controller {
	var $_myErrorMsg = array();
	var $_urlLogin = array('controller' => 'members', 'action' => 'home',);
	var $_urlRegister = array('controller' => 'users', 'action' => 'register',);
	var $sessionUserName = 'statics.userid';
	
	
	function beforeRender()
	{
		$this->set('navi', ($this->Session->check($this->sessionUserName)) ? 'navi_login' : 'navi_not_login');
	}
	
	function _sendMail($datas = array())
	{
		if(empty($datas)){return false;}
		
		$result = true;
		
		vendor('phpmailer/jphpmailer');
		$mail = new JPHPMailer();
		$mail->set('in_enc', 'UTF-8');
		$mail->SetLanguage('ja');
		
		$mail->IsSMTP();
		$mail->set('SMTPAuth', true);
		$mail->set('Host', Configure::read('SMTP.Host'));
		$mail->set('Port', Configure::read('SMTP.Port'));
		$mail->set('Username', Configure::read('SMTP.Username'));
		$mail->set('Password', Configure::read('SMTP.Password'));
		
		foreach($datas as $data){
			$body = '';
			ob_start();
			$this->render(null, '/email/text/default', $data['viewpath']);
			$body = ob_get_clean();
			
			//メールの要素をセット
			$mail->addTo($data['mailaddress']);
			$mail->setSubject($data['subject']);
			$mail->setBody($body);
			$mail->setFrom(Configure::read('Mail.From'), Configure::read('Mail.FromName'));
			
			//メール送信
			if(!$mail->send()){
				$result = false;
				$this->_myErrorMsg[] = "メールが送信できませんでした。エラー:".$mail->getErrorMessage();
				break;
			}
			$mail->ClearAttachments();
			$mail->ClearAllRecipients();
		}
		return $result;
	}
	
	
}
?>